home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
JCSM Shareware Collection 1993 November
/
JCSM Shareware Collection - 1993-11.iso
/
cl720
/
commgeoj.lzh
/
CGDEMO2.C
< prev
next >
Wrap
Text File
|
1993-06-15
|
57KB
|
1,843 lines
#define LINT_ARGS
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cg.h"
#define C_DEG_TO_RAD ((real) 0.0174532) /* 3.1415926 / 180.0 */
#define C_CONTINUE 22
#define C_POINT_MENU 6
struct t_menu_item
{
char item[12];
int return_value;
int next_menu;
};
int current_menu;
int menus[8] = {0, 6, 8, 9, 17, 26, 35};
char menu_title[6][12] = {"MAIN",
"",
"",
"LINES",
"CIRCLES",
"GET POINT"};
struct t_menu_item menu_items[35] = {"About CG", 1, 2,
"Points", 20, 0,
"Lines", 0, 4,
"Circles", 0, 5,
"Delete", 21, 0,
"Exit", 2, 0,
"Continue", 22, 0,
"Return", 0, 1,
"Return", 0, 1,
"2 pts", 12, 0,
"Horizontal", 13, 0,
"Vertical", 14, 0,
"Parallel", 15, 0,
"Perp To", 16, 0,
"Tan Arc", 18, 0,
"Tan 2 Arcs", 19, 0,
"Return", 0, 1,
"3 points", 3, 0,
"Tan Ln Pt", 4, 0,
"Tan Ln 2 Pts", 5, 0,
"Tan 2 Lines", 6, 0,
"Tan 2 Lns Pt", 7, 0,
"Tan 3 Lines", 8, 0,
"Tan 2 Arcs", 9, 0,
"Tan Arc Ln", 11, 0,
"Return", 0, 1,
"Element", 201, 0,
"Around Arc", 202, 0,
"Along Line", 203, 0,
"Int 2 Lines", 204, 0,
"Int Arc Ln", 205, 0,
"Int 2 Arcs", 206, 0,
"Coordinate", 207, 0,
"Screen", 208, 0,
"Return", 209, 0};
struct t_menu_item fixed_menu_items[6] = {"ZOOM ", 101, 0,
"PAN ", 102, 0,
"FULL ", 103, 0,
"SVIEW ", 104, 0,
"RVIEW ", 105, 0,
"CLEAR ", 106, 0};
char intro[33][45] =
{"CommonGeometry is a library of C functions",
"that construct 2D geometries, for example ",
"a LINE TANGENT to 2 ARCS passing through a",
"POINT or a CIRCLE TANGENT to 2 ARCS with a",
"given RADIUS, or calculate geometric ",
"relationships, such as the INTERSECTION of",
"2 ARCS, the INTERSECTION of a LINE and an ",
"ARC, and the DIRECTION from a POINT to a ",
"LINE. ",
" ",
"CommonGeometry can be used as a building ",
"block for CAD, CAM or CAE applications, as",
"well as many others. CommonGeometry can be",
"used with CommonGraphics or any other ",
"graphics library. ",
"CommonGeometry, like CommonGraphics, is a ",
"portable library that lets you to develop ",
"complex graphics applications across a ",
"variety of operating systems hardware ",
"platforms and graphics environments. ",
" ",
"This program demonstrates many of the ",
"functions in CommonGeometry. The menus are",
"arranged like those of a CAD program. All ",
"of the graphics you see were developed ",
"using CommonGraphics. ",
"Copyright 1993 by Rialto Software ",
"4179 Woodland Dr. Suite 15B ",
"Ann Arbor MI 48103 (313) 426-5295 ",
"All rights reserved. ",
" ",
"CommonGeometry and CommonGraphics are ",
"trademarks of Rialto Software "};
t_world_coord color_menu;
int current_menu;
t_world_coord default_point_menu;
struct t_device device_params;
real distance;
long element_id;
t_world_coord fixed_menu_center;
t_world_coord graphic_ll;
t_world_coord graphic_ur;
int i;
t_world_coord menu_center;
bool menu_highlighted;
t_world_coord menu_item_highlight_pt;
int menu_highlight_item;
t_world_coord menu_ll;
t_world_coord menu_ur;
struct t_request_buffer pick_buffer;
t_world_coord pts[6];
bool return_menu_item_selected;
int save_current_menu;
t_world_coord save_ll;
t_world_coord save_ur;
t_world_coord text_ll;
t_ndc_coord viewport_ll;
t_ndc_coord viewport_ur;
int fixed_index;
int menu_index;
bool prompt_interrupted;
void display_menu (int);
void display_fixed_menu (void);
void display_color_menu (void);
int find_menu_picked (void);
bool check_menu_picked (void);
void process_fixed_menu (void);
bool process_point_menu (t_world_coord);
bool valid_prompt (t_name_set, t_name_set, char *);
bool get_point (bool, t_world_coord);
void display_about_cg_info (void);
void point (void);
void delete_element (void);
void line_2pts (void);
void line_pt_angle_distance (real);
void line_parallel (void);
void line_perpendicular (void);
void line_tan_arc (void);
void line_tan_2arcs (void);
void circle_3pts (void);
void circle_tan_line_pt (void);
void circle_tan_line_2pts (void);
void circle_tan_2lines (void);
void circle_tan_2lines_pt (void);
void circle_tan_3lines (void);
void circle_tan_2arcs (void);
void circle_tan_arc_line (void);
void zoom (void);
void main (void);
/**/
void display_menu (int menu_number)
{
int index;
struct t_attributes attributes;
t_world_coord pt;
t_world_coord text_pt;
t_world_coord tmp_pt;
cg_open_non_retained_structure ("MENU");
cg_empty_structure ("MENU");
cg_inquire_primitive_attributes (&attributes);
cg_set_text_color (RED);
cg_set_interior_style (FILL);
cg_set_line_style (SOLID);
text_pt[0] = menu_center[0] - 20.0;
text_pt[1] = menu_center[1] - 10.0;
cg_draw_text (STRING_TEXT, text_pt, menu_title[menu_number - 1], 0.0, 0.0, 0.0);
cg_set_text_color (WHITE);
pt[0] = menu_center[0];
pt[1] = menu_center[1] - 20.0;
for (index = menus[menu_number - 1]; index < menus[menu_number]; index++)
{
cg_set_line_color (BLACK);
tmp_pt[0] = pt[0] - 4.0;
tmp_pt[1] = pt[1] - 4.0;
cg_draw_rectangle (tmp_pt, 90.0, 15.0, 5.0, 0.0);
cg_set_line_color (RED);
cg_draw_rectangle (pt, 90.0, 15.0, 5.0, 0.0);
text_pt[0] = pt[0] - 40.0;
text_pt[1] = pt[1] - 3.0;
cg_draw_text (STRING_TEXT, text_pt, menu_items[index].item, 0.0, 0.0, 0.0);
pt[1] -= 25.0;
}
cg_set_interior_style (EMPTY);
cg_open_structure ("S1");
cg_set_line_color (attributes.color);
cg_set_text_color (attributes.text_color);
menu_highlighted = FALSE;
current_menu = menu_number;
}
/**/
void display_fixed_menu ()
{
int index;
t_world_coord pt;
t_world_coord text_pt;
t_world_coord tmp_pt;
cg_set_window ("FIXED VIEW", 1.0, 20.0);
cg_inquire_view_transformation ("FIXED VIEW", viewport_ll, viewport_ur,
menu_ll, menu_ur);
fixed_menu_center[0] = menu_ll[0];
fixed_menu_center[1] = menu_ll[1];
pt[0] = menu_ll[0] + 25.0;
pt[1] = 1.0;
cg_open_non_retained_structure ("FIXED MENU");
cg_post_structure_to_view ("FIXED MENU", "FIXED VIEW");
cg_set_text_color (WHITE);
cg_set_interior_style (FILL);
cg_set_line_style (SOLID);
for (index = 0; index < 6; index++)
{
cg_set_line_color (BLACK);
tmp_pt[0] = pt[0] - 3.0;
tmp_pt[1] = pt[1] - 3.0;
cg_draw_rectangle (tmp_pt, 40.0, 15.0, 5.0, 0.0);
cg_set_line_color (RED);
cg_draw_rectangle (pt, 40.0, 15.0, 5.0, 0.0);
text_pt[0] = pt[0] - 15.0;
text_pt[1] = pt[1] - 3.0;
cg_draw_text (STRING_TEXT, text_pt, fixed_menu_items[index].item, 0.0, 0.0, 0.0);
pt[0] += 50.0;
}
cg_set_interior_style (EMPTY);
}
/**/
void display_color_menu ()
{
int color_index;
int i;
int j;
t_world_coord pt;
cg_set_window ("COLOR VIEW", 1.0, 20.0);
cg_inquire_view_transformation ("COLOR VIEW", viewport_ll, viewport_ur,
menu_ll, menu_ur);
pt[0] = menu_ll[0] + 5.0;
pt[1] = menu_ll[1] + 2.0;
color_menu[0] = menu_ll[0];
color_menu[1] = menu_ll[1];
cg_open_non_retained_structure ("COLOR MENU");
cg_post_structure_to_view ("COLOR MENU", "COLOR VIEW");
cg_set_interior_style (FILL);
cg_set_line_style (SOLID);
color_index = 0;
for (i = 0; i < 4; i++)
{
pt[0] = menu_ll[0] + 5.0;
for (j = 0; j < 4; j++)
{
cg_set_line_color (color_index);
cg_set_interior_style (FILL);
cg_draw_rectangle (pt, 6.0, 3.0, 0.0, 0.0);
cg_set_line_color (BLACK);
cg_set_interior_style (EMPTY);
cg_draw_rectangle (pt, 6.0, 3.0, 0.0, 0.0);
pt[0] += 8.0;
color_index++;
}
pt[1] += 5.0;
}
cg_set_interior_style (EMPTY);
}
/**/
int find_menu_picked ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
cg_open_structure ("S1");
cg_set_element_identifier ((long) 0);
while (TRUE)
{
if (!prompt_interrupted)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
cg_request_input (allowed_classes, allowed_responses,
"Select menu item", &pick_buffer);
}
prompt_interrupted = FALSE;
if (check_menu_picked ())
{
if (menu_index > -1 )
{
if (menu_items[menu_index].next_menu != 0)
display_menu (menu_items[menu_index].next_menu);
return (menu_items[menu_index].return_value);
}
else
if (fixed_index > -1)
{
process_fixed_menu ();
if (prompt_interrupted)
return (FALSE);
}
else
{
prompt_interrupted = TRUE;
return (FALSE);
}
}
}
}
/**/
bool check_menu_picked ()
{
int color_index;
int i;
int j;
t_world_coord pt;
menu_index = -1;
fixed_index = -1;
return_menu_item_selected = FALSE;
if (strcmp (pick_buffer.view_name, "MENU VIEW") == 0)
{
pt[0] = menu_center[0] - 45.0;
pt[1] = menu_center[1] - 27.5;
for (menu_index = menus[current_menu - 1];
menu_index < menus[current_menu]; menu_index++)
{
if (((pick_buffer.v.location[0] >= pt[0]) &&
(pick_buffer.v.location[0] <= (pt[0] + 90.0))) &&
((pick_buffer.v.location[1] >= pt[1]) &&
(pick_buffer.v.location[1] <= (pt[1] + 15.0))))
{
cg_open_non_retained_structure ("MENU");
if (menu_highlighted)
{
cg_set_text_color (WHITE);
cg_draw_text (STRING_TEXT, menu_item_highlight_pt,
menu_items[menu_highlight_item].item, 0.0, 0.0, 0.0);
}
menu_item_highlight_pt[0] = menu_center[0] - 40.0;
menu_item_highlight_pt[1] = pt[1] + 4.5;
cg_set_text_color (BLACK);
cg_draw_text (STRING_TEXT, menu_item_highlight_pt,
menu_items[menu_index].item, 0.0, 0.0, 0.0);
menu_highlighted = TRUE;
menu_highlight_item = menu_index;
cg_open_structure ("S1");
return_menu_item_selected = strcmp (menu_items[menu_index].item, "Return") == 0;
return (TRUE);
}
pt[1] -= 25.0;
}
}
else
if (strcmp (pick_buffer.view_name, "FIXED VIEW") == 0)
{
pt[0] = fixed_menu_center[0];
pt[1] = fixed_menu_center[1];
for (fixed_index = 0; fixed_index < 6; fixed_index++)
{
if (((pick_buffer.v.location[0] >= pt[0]) &&
(pick_buffer.v.location[0] <= (pt[0] + 40.0))) &&
((pick_buffer.v.location[1] >= pt[1]) &&
(pick_buffer.v.location[1] <= (pt[1] + 15.0))))
return (TRUE);
pt[0] += 50.0;
}
}
else
if (strcmp (pick_buffer.view_name, "COLOR VIEW") == 0)
{
pt[0] = color_menu[0] + 2.0;
pt[1] = color_menu[1] + 0.5;
color_index = 0;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
if (((pick_buffer.v.location[0] >= pt[0]) &&
(pick_buffer.v.location[0] <= (pt[0] + 6.0))) &&
((pick_buffer.v.location[1] >= pt[1]) &&
(pick_buffer.v.location[1] <= (pt[1] + 3.0))))
{
cg_set_line_color (color_index);
cg_set_text_color (color_index);
}
pt[0] += 8.0;
color_index++;
}
pt[0] = color_menu[0] + 2.0;
pt[1] += 5.0;
}
}
return (FALSE);
}
void process_fixed_menu ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
t_world_coord tmp_pts[2];
switch (fixed_menu_items[fixed_index].return_value)
{
case 101: /* Zoom */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate lower left corner of new window"))
return;
tmp_pts[0][0] = pick_buffer.v.location[0];
tmp_pts[0][1] = pick_buffer.v.location[1];
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate upper right corner of new window"))
return;
tmp_pts[1][0] = pick_buffer.v.location[0];
tmp_pts[1][1] = pick_buffer.v.location[1];
cg_zoom ("GRAPHIC VIEW", tmp_pts[0], tmp_pts[1]);
cg_inquire_view_transformation ("GRAPHIC VIEW", viewport_ll, viewport_ur,
graphic_ll, graphic_ur);
break;
case 102: /* Pan */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (valid_prompt (allowed_classes, allowed_responses,
"Locate new center of window"))
{
cg_pan ("GRAPHIC VIEW", pick_buffer.v.location);
cg_inquire_view_transformation ("GRAPHIC VIEW", viewport_ll, viewport_ur,
graphic_ll, graphic_ur);
}
break;
case 103: /* Full */
cg_set_window ("GRAPHIC VIEW", (real) 100.0, (real) 1.0);
break;
case 104: /* Save view */
cg_inquire_view_transformation ("GRAPHIC VIEW", viewport_ll,
viewport_ur, save_ll, save_ur);
break;
case 105: /* Restore view */
cg_zoom ("GRAPHIC VIEW", save_ll, save_ur);
break;
case 106: /* Clear */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (valid_prompt (allowed_classes, allowed_responses, "Erase drawing area?"))
{
if ((strcmp (pick_buffer.v.str, "Y") == 0) ||
(strcmp (pick_buffer.v.str, "y") == 0))
{
element_id = 0;
cg_empty_structure ("S1");
cg_zoom ("GRAPHIC VIEW", graphic_ll, graphic_ur);
}
}
break;
default:
break;
}
}
bool process_point_menu (t_world_coord pt)
{
t_name_set allowed_classes;
t_name_set allowed_responses;
real dist1;
real dist2;
real dist3;
struct t_element elem[2];
t_world_coord mid_pt;
t_world_coord tmp_pt[3];
real value;
switch (menu_items[menu_index].return_value)
{
case 201: /* Element */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_all_names_to_set (&allowed_responses);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick any element"))
return (FALSE);
elem[0] = pick_buffer.v.pick.element;
switch (elem[0].type)
{
case MARKER:
pt[0] = elem[0].v.marker.point[0];
pt[1] = elem[0].v.marker.point[1];
break;
case LINE:
tmp_pt[0][0] = pick_buffer.v.pick.location[0];
tmp_pt[0][1] = pick_buffer.v.pick.location[1];
cg_point_midpoint_line (elem[0].v.line.start_pt,
elem[0].v.line.end_pt, mid_pt);
dist1 = cg_distance_between_2pts (elem[0].v.line.start_pt, tmp_pt[0]);
dist2 = cg_distance_between_2pts (elem[0].v.line.end_pt, tmp_pt[0]);
dist3 = cg_distance_between_2pts (mid_pt, tmp_pt[0]);
if ((dist1 <= dist2) || (dist1 <= dist3))
{
pt[0] = elem[0].v.line.start_pt[0];
pt[1] = elem[0].v.line.start_pt[1];
}
else
if (dist2 <= dist3)
{
pt[0] = elem[0].v.line.end_pt[0];
pt[1] = elem[0].v.line.end_pt[1];
}
else
{
pt[0] = mid_pt[0];
pt[1] = mid_pt[1];
}
break;
case CIRCLE:
pt[0] = elem[0].v.circle.center[0];
pt[1] = elem[1].v.circle.center[1];
break;
case ARC:
break;
default:
pt[0] = 0.0;
pt[1] = 0.0;
break;
}
break;
case 202: /* Around arc */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, CIRCLE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick arc or circle"))
return (FALSE);
elem[0] = pick_buffer.v.pick.element;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses,
"Enter angle around arc"))
return (FALSE);
value = atof (pick_buffer.v.str);
cg_point_around_arc (elem[0].v.circle.center, elem[0].v.circle.radius,
value, pt);
break;
case 203: /* Along line */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick line near reference point"))
return (FALSE);
elem[0] = pick_buffer.v.pick.element;
tmp_pt[0][0] = pick_buffer.v.pick.location[0];
tmp_pt[0][1] = pick_buffer.v.pick.location[1];
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses,
"Enter distance along line"))
return (FALSE);
value = atof (pick_buffer.v.str);
cg_point_along_line (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
value, tmp_pt[0], pt);
break;
case 204: /* Int 2 lines */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 1st line"))
return (FALSE);
elem[0] = pick_buffer.v.pick.element;
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 2nd line"))
return (FALSE);
elem[1] = pick_buffer.v.pick.element;
if (!cg_intersect_2lines (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
elem[1].v.line.start_pt, elem[1].v.line.end_pt,
pt))
return (FALSE);
break;
case 205: /* Int arc line */
allowed_classes = 0;
cg_add_name_to_set (&allowed_classes, PICK);
allowed_responses = 0;
cg_add_name_to_set (&allowed_responses, CIRCLE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick circle near point of intersection"))
return (FALSE);
elem[0] = pick_buffer.v.pick.element;
tmp_pt[0][0] = pick_buffer.v.pick.location[0];
tmp_pt[0][1] = pick_buffer.v.pick.location[1];
allowed_responses = 0;
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick line"))
return (FALSE);
elem[1] = pick_buffer.v.pick.element;
if (!cg_intersect_arc_line (elem[0].v.circle.center, elem[0].v.circle.radius,
elem[1].v.line.start_pt, elem[1].v.line.end_pt,
tmp_pt[0], pt))
return (FALSE);
break;
case 206: /* Int 2 arcs */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, CIRCLE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 1st circle near point of intersection"))
return (FALSE);
elem[0] = pick_buffer.v.pick.element;
tmp_pt[0][0] = pick_buffer.v.pick.location[0];
tmp_pt[0][1] = pick_buffer.v.pick.location[1];
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 2nd circle"))
return (FALSE);
elem[1] = pick_buffer.v.pick.element;
if (!cg_intersect_2arcs (elem[0].v.circle.center, elem[0].v.circle.radius,
elem[1].v.circle.center, elem[1].v.circle.radius,
tmp_pt[0], pt))
return (FALSE);
break;
case 207: /* Coordinate */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses,
"Enter X coordinate"))
return (FALSE);
pt[0] = atof (pick_buffer.v.str);
if (!valid_prompt (allowed_classes, allowed_responses,
"Enter Y coordinate"))
return (FALSE);
pt[1] = atof (pick_buffer.v.str);
break;
case 208: /* Screen */
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate point"))
return (FALSE);
pt[0] = pick_buffer.v.location[0];
pt[1] = pick_buffer.v.location[1];
break;
case 209: /* Return */
prompt_interrupted = TRUE;
return (FALSE);
break;
}
return (TRUE);
}
bool valid_prompt (t_name_set allowed_classes,
t_name_set allowed_responses,
char *prompt)
{
t_name_set local_allowed_classes;
local_allowed_classes = allowed_classes;
cg_add_name_to_set (&local_allowed_classes, LOCATE);
prompt_interrupted = FALSE;
while (TRUE)
{
cg_request_input (local_allowed_classes, allowed_responses, prompt,
&pick_buffer);
if (pick_buffer.type == STRING)
return (TRUE);
else
if (strcmp (pick_buffer.view_name, "GRAPHIC VIEW") == 0)
if (pick_buffer.type == LOCATE)
{
if (cg_inquire_name_set (allowed_classes, LOCATE))
return (TRUE);
}
else
return (TRUE);
else
if (check_menu_picked ())
{
if (fixed_index > -1)
{
process_fixed_menu ();
if (prompt_interrupted)
return (FALSE);
}
else
{
if (current_menu == C_POINT_MENU)
{
if (!return_menu_item_selected)
{
default_point_menu[0] = pick_buffer.v.location[0];
default_point_menu[1] = pick_buffer.v.location[1];
}
}
prompt_interrupted = TRUE;
return (FALSE);
}
}
}
}
bool get_point (bool redisplay_menu,
t_world_coord pt)
{
bool done;
bool return_value;
prompt_interrupted = FALSE;
display_menu (C_POINT_MENU);
done = FALSE;
while (!done)
{
pick_buffer.type = LOCATE;
strcpy (pick_buffer.view_name, "MENU VIEW");
pick_buffer.v.location[0] = default_point_menu[0];
pick_buffer.v.location[1] = default_point_menu[1];
check_menu_picked ();
process_point_menu (pt);
if (prompt_interrupted)
{
if (return_menu_item_selected)
done = TRUE;
return_value = FALSE;
}
else
{
done = TRUE;
return_value = TRUE;
}
}
if ((return_value == FALSE) || (redisplay_menu))
{
display_menu(save_current_menu);
prompt_interrupted = FALSE;
}
return (return_value);
}
/**/
void display_about_cg_info ()
{
t_world_coord pt;
cg_set_structure_visibility ("S1", OFF);
cg_open_structure ("INFO");
cg_post_structure_to_view ("INFO", "GRAPHIC VIEW");
cg_set_text_color (WHITE);
pt[0] = graphic_ll[0] + 10.0;
pt[1] = graphic_ur[0] - 10.0;
for (i = 0; i < 15; i++)
{
cg_draw_text (STRING_TEXT, pt, intro[i], 0.0, 0.0, 0.0);
pt[1] -= 5.0;
}
if (find_menu_picked () == C_CONTINUE)
{
cg_open_structure ("INFO");
cg_empty_structure ("INFO");
cg_set_text_color (WHITE);
pt[0] = graphic_ll[0] + 10.0;
pt[1] = graphic_ur[0] - 10.0;
for (i = 15; i < 26; i++)
{
cg_draw_text (STRING_TEXT, pt, intro[i], 0.0, 0.0, 0.0);
pt[1] -= 5.0;
}
if (find_menu_picked () == C_CONTINUE)
{
display_menu (3);
cg_open_structure ("INFO");
cg_empty_structure ("INFO");
cg_set_text_color (WHITE);
pt[0] = graphic_ll[0] + 10.0;
pt[1] = graphic_ur[0] - 10.0;
for (i = 26; i < 33; i++)
{
cg_draw_text (STRING_TEXT, pt, intro[i], 0.0, 0.0, 0.0);
pt[1] -= 5.0;
}
find_menu_picked ();
}
}
cg_delete_structure ("INFO");
cg_set_structure_visibility ("S1", ON);
}
void point ()
{
save_current_menu = current_menu;
while (TRUE)
{
if (!get_point (FALSE, pts[0]))
return;
cg_set_element_identifier (element_id++);
cg_draw_marker (PLUS, pts[0]);
}
display_menu (save_current_menu);
}
void delete_element ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_all_names_to_set (&allowed_responses);
if (!valid_prompt (allowed_classes, allowed_responses, "Pick element to delete"))
return;
cg_delete_element ("S1", pick_buffer.v.pick.element.id);
}
}
void line_2pts ()
{
save_current_menu = current_menu;
while (TRUE)
{
if (!get_point (FALSE, pts[0]))
return;
if (!get_point (TRUE, pts[1]))
return;
cg_set_element_identifier (element_id++);
cg_draw_line (pts[0], pts[1]);
}
display_menu (save_current_menu);
}
void line_pt_angle_distance (real angle)
{
t_name_set allowed_classes;
t_name_set allowed_responses;
real distance;
t_world_coord end_pt;
save_current_menu = current_menu;
while (TRUE)
{
if (!get_point (FALSE, pts[0]))
return;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses, "Enter distance"))
return;
distance = atof (pick_buffer.v.str);
if (angle == (real) 0.0)
{
end_pt[0] = pts[0][0] + distance;
end_pt[1] = pts[0][1];
}
else
{
end_pt[0] = pts[0][0];
end_pt[1] = pts[0][1] + distance;
}
// cg_line_pt_angle_distance (pts[0], angle, distance, end_pt);
cg_set_element_identifier (element_id++);
cg_draw_line (pts[0], end_pt);
}
display_menu (save_current_menu);
}
void line_parallel ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
struct t_element elem[1];
t_world_coord new_start_pt;
t_world_coord new_end_pt;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick line"))
return;
elem[0] = pick_buffer.v.pick.element;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
while (TRUE)
{
if (!valid_prompt (allowed_classes, allowed_responses, "Enter distance"))
return;
distance = atof (pick_buffer.v.str);
cg_line_parallel (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
distance, new_start_pt, new_end_pt);
cg_set_element_identifier (element_id++);
cg_draw_line (new_start_pt, new_end_pt);
}
}
void line_perpendicular ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
struct t_element elem[1];
t_world_coord new_pt;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick line"))
return;
elem[0] = pick_buffer.v.pick.element;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
while (TRUE)
{
if (!get_point (TRUE, pts[0]))
return;
cg_line_perpendicular (pts[0],
elem[0].v.line.start_pt, elem[0].v.line.end_pt,
new_pt);
cg_set_element_identifier (element_id++);
cg_draw_line (pts[0], new_pt);
}
}
void line_tan_arc ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
struct t_element elem[1];
t_world_coord new_end_pt;
save_current_menu = current_menu;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, CIRCLE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick circle near point of tangency"))
return;
elem[0] = pick_buffer.v.pick.element;
pts[0][0] = pick_buffer.v.pick.location[0];
pts[0][1] = pick_buffer.v.pick.location[1];
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!get_point (TRUE, pts[1]))
return;
cg_line_tan_arc (pts[1], elem[0].v.circle.center,
elem[0].v.circle.radius, pts[0], new_end_pt);
cg_set_element_identifier (element_id++);
cg_draw_line (pick_buffer.v.location, new_end_pt);
}
display_menu (save_current_menu);
}
void line_tan_2arcs ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
struct t_element elem[2];
t_world_coord line_start_pt;
t_world_coord line_end_pt;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, CIRCLE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 1st circle near point of tangency"))
return;
elem[0] = pick_buffer.v.pick.element;
pts[0][0] = pick_buffer.v.pick.location[0];
pts[0][1] = pick_buffer.v.pick.location[1];
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 2nd circle near point of tangency"))
return;
elem[1] = pick_buffer.v.pick.element;
pts[1][0] = pick_buffer.v.pick.location[0];
pts[1][1] = pick_buffer.v.pick.location[1];
cg_line_tan_2arcs (elem[0].v.circle.center, elem[0].v.circle.radius,
elem[1].v.circle.center, elem[1].v.circle.radius,
pts[0], pts[1], line_start_pt, line_end_pt);
cg_set_element_identifier (element_id++);
cg_draw_line (line_start_pt, line_end_pt);
}
}
void circle_3pts ()
{
t_world_coord center;
real radius;
save_current_menu = current_menu;
while (TRUE)
{
cg_set_element_identifier ((long) 9999);
if (!get_point (FALSE, pts[0]))
return;
cg_draw_marker (PLUS, pts[0]);
if (!get_point (FALSE, pts[1]))
return;
cg_draw_marker (PLUS, pts[1]);
if (!get_point (TRUE, pts[2]))
return;
cg_draw_marker (PLUS, pts[2]);
cg_set_element_identifier ((long) 0);
cg_delete_element ("S1", (long) 9999);
if (cg_circle_3pts (pts[0], pts[1], pts[2], center, &radius))
{
cg_set_element_identifier (element_id++);
cg_draw_circle (center, radius);
}
}
display_menu (save_current_menu);
}
void circle_tan_line_pt ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
t_world_coord center;
struct t_element elem[2];
real radius;
save_current_menu = current_menu;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick line"))
return;
elem[0] = pick_buffer.v.pick.element;
if (!get_point (TRUE, pts[0]))
return;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses, "Enter radius"))
return;
radius = atof (pick_buffer.v.str);
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate point near center of circle"))
return;
pts[1][0] = pick_buffer.v.location[0];
pts[1][1] = pick_buffer.v.location[1];
if (cg_circle_tan_line_pt_radius (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
pts[0], radius, pts[1], center))
{
cg_set_element_identifier (element_id++);
cg_draw_circle (center, radius);
}
}
display_menu (save_current_menu);
}
void circle_tan_line_2pts ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
t_world_coord center;
struct t_element elem[2];
real radius;
save_current_menu = current_menu;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick line"))
return;
elem[0] = pick_buffer.v.pick.element;
if (!get_point (FALSE, pts[0]))
return;
if (!get_point (TRUE, pts[1]))
return;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate point near center of circle"))
return;
pts[2][0] = pick_buffer.v.location[0];
pts[2][1] = pick_buffer.v.location[1];
if (cg_circle_tan_line_2pts (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
pts[0], pts[1], pts[2], center, &radius))
{
cg_set_element_identifier (element_id++);
cg_draw_circle (center, radius);
}
}
display_menu (save_current_menu);
}
void circle_tan_2lines ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
t_world_coord center;
struct t_element elem[2];
real radius;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 1st line"))
return;
elem[0] = pick_buffer.v.pick.element;
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 2st line"))
return;
elem[1] = pick_buffer.v.pick.element;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate side for circle"))
return;
pts[0][0] = pick_buffer.v.location[0];
pts[0][1] = pick_buffer.v.location[1];
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses, "Enter radius"))
return;
radius = atof (pick_buffer.v.str);
if (cg_circle_tan_2lines_radius (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
elem[1].v.line.start_pt, elem[1].v.line.end_pt,
radius, pts[0], center))
{
cg_set_element_identifier (element_id++);
cg_draw_circle (center, radius);
}
}
}
void circle_tan_2lines_pt ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
t_world_coord center;
struct t_element elem[2];
real radius;
save_current_menu = current_menu;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 1st line"))
return;
elem[0] = pick_buffer.v.pick.element;
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 2st line"))
return;
elem[1] = pick_buffer.v.pick.element;
if (!get_point (TRUE, pts[0]))
return;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate side for circle"))
return;
pts[1][0] = pick_buffer.v.location[0];
pts[1][1] = pick_buffer.v.location[1];
if (cg_circle_tan_2lines_pt (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
elem[1].v.line.start_pt, elem[1].v.line.end_pt,
pts[0], pts[1], center, &radius))
{
cg_set_element_identifier (element_id++);
cg_draw_circle (center, radius);
}
}
display_menu (save_current_menu);
}
void circle_tan_3lines ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
t_world_coord center;
struct t_element elem[3];
real radius;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, LINE);
while (TRUE)
{
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 1st line"))
return;
elem[0] = pick_buffer.v.pick.element;
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 2nd line"))
return;
elem[1] = pick_buffer.v.pick.element;
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick 3rd line"))
return;
elem[2] = pick_buffer.v.pick.element;
if (cg_intersect_2lines (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
elem[1].v.line.start_pt, elem[1].v.line.end_pt,
pts[0]) &&
cg_intersect_2lines (elem[0].v.line.start_pt, elem[0].v.line.end_pt,
elem[2].v.line.start_pt, elem[2].v.line.end_pt,
pts[1]) &&
cg_intersect_2lines (elem[1].v.line.start_pt, elem[1].v.line.end_pt,
elem[2].v.line.start_pt, elem[2].v.line.end_pt,
pts[2]))
{
cg_circle_tan_3lines (pts[1], pts[0], pts[2], center, &radius);
cg_set_element_identifier (element_id++);
cg_draw_circle (center, radius);
}
}
}
void circle_tan_2arcs ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
struct t_element elem[2];
t_world_coord new_center;
real radius;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, CIRCLE);
for (i = 0; i < 2; i++)
{
if (!valid_prompt (allowed_classes, allowed_responses, "Pick circle"))
return;
elem[i] = pick_buffer.v.pick.element;
}
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate side for circle"))
return;
pts[0][0] = pick_buffer.v.location[0];
pts[0][1] = pick_buffer.v.location[1];
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses, "Enter radius"))
return;
radius = atof (pick_buffer.v.str);
if (cg_circle_tan_2arcs_radius (elem[0].v.circle.center, elem[0].v.circle.radius,
elem[1].v.circle.center, elem[1].v.circle.radius,
radius, pts[0], new_center))
{
cg_set_element_identifier (element_id++);
cg_draw_circle (new_center, radius);
}
}
}
void circle_tan_arc_line ()
{
t_name_set allowed_classes;
t_name_set allowed_responses;
struct t_element elem[3];
t_world_coord new_center;
real radius;
while (TRUE)
{
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, PICK);
cg_add_name_to_set (&allowed_responses, CIRCLE);
if (!valid_prompt (allowed_classes, allowed_responses, "Pick circle"))
return;
elem[0] = pick_buffer.v.pick.element;
allowed_responses = 0;
cg_add_name_to_set (&allowed_responses, LINE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Pick line"))
return;
elem[1] = pick_buffer.v.pick.element;
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, LOCATE);
if (!valid_prompt (allowed_classes, allowed_responses,
"Locate side for circle"))
return;
pts[0][0] = pick_buffer.v.location[0];
pts[0][1] = pick_buffer.v.location[1];
allowed_classes = 0;
allowed_responses = 0;
cg_add_name_to_set (&allowed_classes, STRING);
if (!valid_prompt (allowed_classes, allowed_responses, "Enter radius"))
return;
radius = atof (pick_buffer.v.str);
if (cg_circle_tan_arc_line_radius (elem[0].v.circle.center,
elem[0].v.circle.radius,
elem[1].v.line.start_pt,
elem[1].v.line.end_pt,
radius, pts[0],
new_center))
{
cg_set_element_identifier (element_id++);
cg_draw_circle (new_center, radius);
}
}
}
void main ()
{
bool done;
cg_initialize ();
cg_inquire_workstation (&device_params);
cg_set_line_color (RED);
cg_set_line_style (SOLID);
viewport_ll[0] = 0.0;
viewport_ll[1] = 0.15;
viewport_ur[0] = 0.25;
viewport_ur[1] = device_params.aspect_ratio;
cg_open_view ("MENU VIEW", viewport_ll, viewport_ur, LIGHT_GRAY, NO_BORDER);
cg_inquire_view_transformation ("MENU VIEW", viewport_ll, viewport_ur,
menu_ll, menu_ur);
menu_center[0] = menu_ll[0] + 50.0;
menu_center[1] = menu_ur[1];
cg_open_non_retained_structure ("MENU");
cg_post_structure_to_view ("MENU", "MENU VIEW");
viewport_ll[0] = 0.25;
viewport_ll[1] = 0.0;
viewport_ur[0] = 1.0;
viewport_ur[1] = 0.05;
cg_open_view ("FIXED VIEW", viewport_ll, viewport_ur, LIGHT_GRAY, NO_BORDER);
viewport_ll[0] = 0.0;
viewport_ll[1] = 0.0;
viewport_ur[0] = 0.25;
viewport_ur[1] = 0.15;
cg_open_view ("COLOR VIEW", viewport_ll, viewport_ur, LIGHT_GRAY, NO_BORDER);
viewport_ll[0] = 0.25;
viewport_ll[1] = 0.05;
viewport_ur[0] = 1.0;
viewport_ur[1] = device_params.aspect_ratio - 0.05;
cg_open_view ("GRAPHIC VIEW", viewport_ll, viewport_ur, CYAN, NO_BORDER);
cg_inquire_view_transformation ("GRAPHIC VIEW", viewport_ll, viewport_ur,
graphic_ll, graphic_ur);
cg_inquire_view_transformation ("GRAPHIC VIEW", viewport_ll,
viewport_ur, save_ll, save_ur);
viewport_ll[0] = 0.25;
viewport_ll[1] = device_params.aspect_ratio - 0.05;
viewport_ur[0] = 1.0;
viewport_ur[1] = device_params.aspect_ratio;
cg_open_view ("TITLE VIEW", viewport_ll, viewport_ur, LIGHT_GRAY, NO_BORDER);
cg_open_non_retained_structure ("S2");
cg_post_structure_to_view ("S2", "TITLE VIEW");
text_ll[0] = -45.0;
text_ll[1] = -1.0;
cg_set_text_color (BLACK);
cg_draw_text (STRING_TEXT, text_ll,
"CommonGeometry (v 1.0) Copyright 1993 Rialto Software",
0.0, 0.0, 0.0);
viewport_ll[0] = 0.26;
viewport_ll[1] = 0.06;
cg_set_string_response (viewport_ll, BLACK, CYAN);
cg_open_structure ("S1");
cg_post_structure_to_view ("S1", "GRAPHIC VIEW");
display_menu (1);
display_fixed_menu ();
display_color_menu ();
cg_set_line_color (RED);
cg_set_text_color (RED);
default_point_menu[0] = (real) -14.945227; /* Element */
default_point_menu[1] = (real) 109.290199;
done = FALSE;
element_id = 0;
prompt_interrupted = TRUE;
while (!done)
{
switch (find_menu_picked ())
{
case 0:
break;
case 1:
display_about_cg_info ();
break;
case 2:
done = TRUE;
break;
case 3: /* Circle 3 points */
circle_3pts ();
break;
case 4: /* Circle tan line pt */
circle_tan_line_pt ();
break;
case 5: /* Circle tan line 2 pts */
circle_tan_line_2pts ();
break;
case 6: /* Circle tan 2 lines */
circle_tan_2lines ();
break;
case 7:
circle_tan_2lines_pt (); /* Circle tan 2 lines pt */
break;
case 8: /* Circle tan 3 lines */
circle_tan_3lines ();
break;
case 9: /* Circle tan 2 arcs */
circle_tan_2arcs ();
break;
case 11: /* Circle tan arc and line */
circle_tan_arc_line ();
break;
case 12: /* Line 2pts */
line_2pts ();
break;
case 13: /* Line horizontal */
line_pt_angle_distance ((real) 0.0);
break;
case 14: /* Line vertical */
line_pt_angle_distance ((real) 90.0);
break;
case 15: /* Line parallel */
line_parallel ();
break;
case 16: /* Line perp to */
line_perpendicular ();
break;
case 18: /* Line tan pt arc */
line_tan_arc ();
break;
case 19: /* Line tan 2 arcs */
line_tan_2arcs ();
break;
case 20: /* Point */
point ();
break;
case 21: /* Delete */
delete_element ();
break;
default:
break;
}
}
cg_terminate ();
}